package com.wc.算法基础课.E第五讲动态规划.数位统计DP.烦人的数学作业;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/17 23:17
 * @description https://www.luogu.com.cn/problem/P4999
 */
public class Main {
    static int mod = (int) 1e9 + 7;
    static int N = 20;
    // f[i] 表示 1 到  i个9的各位数总和
    static long[] f = new long[N];
    // base[i] 表示 10 ^ i
    static long[] base = new long[N];
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int t;
    static long l, r;
    static int[] nums = new int[N];


    public static void main(String[] args) {
        t = sc.nextInt();
        init();
        while (t-- > 0) {
            l = sc.nextLong();
            r = sc.nextLong();
            out.println((dp(r) - dp(l - 1) + mod) % mod);
        }
        out.flush();
    }

    static void init() {
        base[0] = 1;
        for (int i = 1; i <= 18; i++) {
            base[i] = base[i - 1] * 10 % mod;
        }
        f[1] = 45;
        // 数学推导
        for (int i = 2; i <= 18; i++) {
            f[i] = (10 * f[i - 1] + base[i - 1] * f[1]) % mod;
        }
    }

    static long dp(long n) {
        if (n == 0) return 0;
        int len = 0;
        while (n > 0) {
            nums[len++] = (int) (n % 10);
            n /= 10;
        }
        long res = 0;
        long last = 0;

        for (int i = len - 1; i >= 0; i--) {
            int x = nums[i];
            // 左边分支
            if (x > 0) {
                if (x > 1) {
                    // x 代表的是 0 ~ x - 1个，(x - 1) * x / 2 当前位数为0 ~ x - 1时候的个数， last * x 前面和也有 base[i]个
                    res = (res + x * f[i] + (long) (x - 1) * x / 2 * base[i] + last * x * base[i]) % mod;
                } else {
                    // 当只能为1的时候
                    res = (res + f[i] + last * base[i]) % mod;
                }
            }
            // 前面的所有位数之和
            last += x;
            // 加上最后一个数
            if (i == 0) {
                res = (res + last) % mod;
            }
        }
        return res % mod;
    }


    static void test(long r) {
        long res = 0;
        for (long i = 1; i <= r; i++) {
            long n = i;
            while (n > 0) {
                res += n % 10;
                n /= 10;
            }
        }
        System.out.println(res);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
